﻿@model MessageTemplateListLocalModel
@using Nop.Plugin.Misc.MessageDesigner.Models;
@using System.Globalization;
@using Nop.Core.Infrastructure;
@using Nop.Web.Framework;
@using Nop.Web.Framework.UI;
@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
    //page title
    ViewBag.Title = T("Admin.ContentManagement.MessageTemplates").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.ContentManagement.MessageTemplates")
    </div>
    <div class="options">
        <a href="" style="font-size:16px;" onclick="javascript: OpenWindow('@Url.Content("/Plugins/Misc.MessageDesigner/Views/instructions.html")', 800, 600, true); return false;">Instructions</a>
        <a href="@Url.Action("DesignList")" class="plugin-button plugin-button-configure">@T("Plugins.Misc.MessageDesigner.ManageDesigns")</a>
        <a href="@Url.Action("RestoreNopTemplates")" onclick="return confirm('@T("Plugins.Misc.MessageDesigner.RestoreNop.Confirm")');" class="k-button">@T("Plugins.Misc.MessageDesigner.RestoreNop")</a>
    </div>
</div>
@Html.HiddenFor(model => model.MessageDesignId)
<table width="100%">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.SearchStoreId):
        </td>
        <td class="adminData">
            @Html.DropDownList("SearchStoreId", Model.AvailableStores)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="search-templates" class="k-button" value="@T("Admin.Common.Search")" />
        </td>
    </tr>
</table>
<table class="adminContent">
    <tr>
        <td>
            <div id="templates-grid"></div>

            <script>
                $(document).ready(function () {
                    $("#templates-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("ListTemplates", "MiscMessageDesigner"))",
                                    type: "POST",
                                    dataType: "json",
                                    data: additionalData
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors"
                            },
                            error: function (e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            numeric: false,
                            previousNext: false,
                            info: false
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "Name",
                            title: "@T("Admin.ContentManagement.MessageTemplates.Fields.Name")"
                        }, {
                            field: "Subject",
                            title: "@T("Admin.ContentManagement.MessageTemplates.Fields.Subject")"
                        }, {
                            field: "IsActive",
                            title: "@T("Admin.ContentManagement.MessageTemplates.Fields.IsActive")",
                            width: 100,
                            headerAttributes: { style: "text-align:center" },
                            attributes: { style: "text-align:center" },
                            template: '<img src="@Url.Content("~/Administration/Content/images/")active-#=IsActive#.gif" />'
                        }, {
                            field: "DesignName",
                            title: "@T("Plugins.Misc.MessageDesigner.Fields.DesignName")"
                        }, {
                            field: "Id",
                            title: "@T("Plugins.Misc.MessageDesigner.Fields.View")",
                            width: 100,
                            template: '<a  onclick="javascript:OpenWindow(\'@(Url.Action("ViewTemplate"))?templateId=#=Id#\', 800, 800, true); return false;" >@T("Plugins.Misc.MessageDesigner.Fields.View")</a>'
                        }, {
                            field: "Id",
                            title: "@T("Admin.Common.Edit")",
                            width: 100,
                            template: '<a href="@Url.Content("~/MessageTemplate/Edit/")#=Id#">@T("Admin.Common.Edit")</a>'
                        }]
                    });
                });
            </script>

            <script type="text/javascript">

                $(document).ready(function () {
                    //search button
                    $('#search-templates').click(function () {
                        //search
                        var grid = $('#templates-grid').data('kendoGrid');
                        grid.dataSource.read();
                    });
                });

                function additionalData() {
                    return {
                        SearchStoreId: $('#SearchStoreId').val(),
                        MessageDesignId: $('#MessageDesignId').val()
                    };
                }
            </script>
        </td>
    </tr>
</table>
